﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VentHost.Lib.Objects;

namespace VentHost.Lib
{
    public class Data
    {
        public List<Server> GetServers()
        {
            List<Server> lst = new List<Server>();
            string sql = "SELECT Id, ServerName, Running FROM Servers ORDER BY Id";

            using (DB db = new DB())
            {
                System.Data.SqlClient.SqlDataReader dr = db.GetDataReader(sql);
                while (dr.Read())
                {
                    Server s = new Server();
                    s.Id =  (int)dr["Id"];
                    s.ServerName = (string)dr["ServerName"];
                    s.Running = (bool)dr["Running"];
                    lst.Add(s);
                }
            }

            return lst;
        }

        public List<Setting> GetSettings(int ServerId)
        {
            List<Setting> lst = new List<Setting>();
            string sql = "sp_GetSettings";

            using (DB db = new DB())
            {
                List<System.Data.IDataParameter> parms = new List<System.Data.IDataParameter>();
                parms.Add(new System.Data.SqlClient.SqlParameter("@ServerId", ServerId));

                System.Data.SqlClient.SqlDataReader dr = db.GetDataReader(sql, System.Data.CommandType.StoredProcedure, parms);
                while (dr.Read())
                {
                    Setting s = new Setting();
                    s.Id = (int)dr["Id"];
                    s.ServerId = ServerId;
                    s.SettingName = (string)dr["SettingName"];
                    s.SettingValue = (string)dr["SettingValue"];
                    s.SettingDesc = "";
                    lst.Add(s);
                }
            }

            return lst;
        }

    }
}
